(function(){
    document.addEventListener("mousedown",function (e) {
        var ele = e.target;
        var mx = e.clientX,
            my = e.clientY;
        if(ele.getAttribute("drag") === "fengyu") {
            ele.style.cursor = "pointer";
            addDrag(ele);
        }else{
            return;
        }
        document.addEventListener("mousemove",mousemove);
        document.addEventListener("mouseup",mouseup);
        function mousemove(e) {
            ele.style.top = e.clientY - my + ele.top +"px";
            ele.style.left = e.clientX - mx + ele.left+"px";
        }
        function mouseup() {
            ele.style.cursor = "default";
            document.removeEventListener("mousemove",mousemove);
            document.removeEventListener("mouseup",mouseup);
        }
    });
    function addDrag(obj) {
        var objStyle = getComputedStyle(obj);
        if(!obj.offsetTop){
            obj.parentNode.style.position = "relative";
            obj.style.position = "absolute";
            obj.style.top = objStyle.marginTop;
            obj.style.left = objStyle.marginLeft;
        }
        obj.top = obj.offsetTop;
        obj.left = obj.offsetLeft;
    }
})();